/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaPrincipal.java
 *
 * Created on 11/08/2010, 10:13:29
 */
package view;

import DAO.ClienteDAO;
import DAO.EstoqueDAO;
import DAO.ProdutoDAO;
import controller.Cliente;
import controller.Produto;
import java.awt.Dimension;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Alcivando
 */
public class TelaPrincipal extends javax.swing.JFrame {



    CadastroClientes cadCliente;
    private DefaultTableModel modeloAniversario;
    private DefaultTableModel modeloEstoque;
    private ClienteDAO dao;

     public TelaPrincipal() {
        initComponents();
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dpDesktop = new javax.swing.JDesktopPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tabEstoque = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabAniversario = new javax.swing.JTable();
        ImageIcon icon = new ImageIcon("C:/Users/Alcivando/Documents/NetBeansProjects/Shannon Commercial/images/logo.gif");
        jLabel2 = new javax.swing.JLabel(icon);
        jPanel4 = new javax.swing.JPanel();
        btnFornecedor = new javax.swing.JButton();
        btnProduto = new javax.swing.JButton();
        btnFuncionario = new javax.swing.JButton();
        btnCliente = new javax.swing.JButton();
        btnVendas = new javax.swing.JButton();
        btnContasReceber = new javax.swing.JButton();
        btnCompras = new javax.swing.JButton();
        btnContasPagar = new javax.swing.JButton();
        btnPesquisarEstoque = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        menuCadastro = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        FornecedorCadastro = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        menuMovimento = new javax.swing.JMenu();
        menuItemVenda = new javax.swing.JMenuItem();
        menuItemCompra = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JPopupMenu.Separator();
        menuItemPagar = new javax.swing.JMenuItem();
        menuItemReceber = new javax.swing.JMenuItem();
        menuItemControleEstoque = new javax.swing.JMenu();
        menuItemEstoque = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Shannon Commercial");

        dpDesktop.setBackground(new java.awt.Color(0, 0, 102));
        dpDesktop.setName("Shannon Commercial"); // NOI18N

        jPanel3.setBackground(new java.awt.Color(0, 0, 102));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Alerta de Estoque", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(255, 255, 255))); // NOI18N

        tabEstoque.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabEstoque.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabEstoqueMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tabEstoque);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 348, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBounds(410, 220, 380, 150);
        dpDesktop.add(jPanel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanel2.setBackground(new java.awt.Color(0, 0, 102));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Aniversários do Dia", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(255, 255, 255))); // NOI18N

        tabAniversario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabAniversario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabAniversarioMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tabAniversario);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel2.setBounds(10, 220, 380, 150);
        dpDesktop.add(jPanel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/logo.gif"))); // NOI18N
        jLabel2.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jLabel2.setBounds(200, 370, 340, 160);
        dpDesktop.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 790, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 21, Short.MAX_VALUE)
        );

        jPanel4.setBounds(0, 530, 790, -1);
        dpDesktop.add(jPanel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnFornecedor.setText("Cad.Fornecedor");
        btnFornecedor.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnFornecedor.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFornecedorActionPerformed(evt);
            }
        });
        btnFornecedor.setBounds(330, 10, 130, 80);
        dpDesktop.add(btnFornecedor, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnProduto.setText("Cad.Produtos");
        btnProduto.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnProduto.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProdutoActionPerformed(evt);
            }
        });
        btnProduto.setBounds(480, 10, 130, 80);
        dpDesktop.add(btnProduto, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnFuncionario.setText("Cad.Funcionário");
        btnFuncionario.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnFuncionario.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnFuncionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFuncionarioActionPerformed(evt);
            }
        });
        btnFuncionario.setBounds(180, 10, 130, 80);
        dpDesktop.add(btnFuncionario, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnCliente.setText("Cad.Clientes");
        btnCliente.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCliente.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnClienteActionPerformed(evt);
            }
        });
        btnCliente.setBounds(30, 10, 130, 80);
        dpDesktop.add(btnCliente, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnVendas.setText("Fazer Vendas");
        btnVendas.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnVendas.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnVendas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVendasActionPerformed(evt);
            }
        });
        btnVendas.setBounds(110, 110, 130, 80);
        dpDesktop.add(btnVendas, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnContasReceber.setText("Ver Contas a Receber");
        btnContasReceber.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnContasReceber.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnContasReceber.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnContasReceberActionPerformed(evt);
            }
        });
        btnContasReceber.setBounds(410, 110, 140, 80);
        dpDesktop.add(btnContasReceber, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnCompras.setText("Fazer Compras");
        btnCompras.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCompras.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCompras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnComprasActionPerformed(evt);
            }
        });
        btnCompras.setBounds(630, 10, 130, 80);
        dpDesktop.add(btnCompras, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnContasPagar.setText("Ver Contas a Pagar");
        btnContasPagar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnContasPagar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnContasPagar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnContasPagarActionPerformed(evt);
            }
        });
        btnContasPagar.setBounds(260, 110, 130, 80);
        dpDesktop.add(btnContasPagar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnPesquisarEstoque.setText("Pesquisar Estoque");
        btnPesquisarEstoque.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnPesquisarEstoque.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnPesquisarEstoque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarEstoqueActionPerformed(evt);
            }
        });
        btnPesquisarEstoque.setBounds(570, 110, 130, 80);
        dpDesktop.add(btnPesquisarEstoque, javax.swing.JLayeredPane.DEFAULT_LAYER);

        menuCadastro.setText("Cadastros");

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("Clientes");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        menuCadastro.add(jMenuItem2);

        FornecedorCadastro.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        FornecedorCadastro.setText("Fornecedor");
        FornecedorCadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FornecedorCadastroActionPerformed(evt);
            }
        });
        menuCadastro.add(FornecedorCadastro);

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem5.setText("Funcionário");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        menuCadastro.add(jMenuItem5);

        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem6.setText("Produto");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        menuCadastro.add(jMenuItem6);

        jMenuBar1.add(menuCadastro);

        menuMovimento.setText("Movimento");
        menuMovimento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuMovimentoActionPerformed(evt);
            }
        });

        menuItemVenda.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        menuItemVenda.setText("Vendas");
        menuItemVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemVendaActionPerformed(evt);
            }
        });
        menuMovimento.add(menuItemVenda);

        menuItemCompra.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        menuItemCompra.setText("Compras");
        menuItemCompra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemCompraActionPerformed(evt);
            }
        });
        menuMovimento.add(menuItemCompra);
        menuMovimento.add(jSeparator3);

        menuItemPagar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        menuItemPagar.setText("contas a Pagar");
        menuItemPagar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemPagarActionPerformed(evt);
            }
        });
        menuMovimento.add(menuItemPagar);

        menuItemReceber.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        menuItemReceber.setText("contas a Receber");
        menuItemReceber.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemReceberActionPerformed(evt);
            }
        });
        menuMovimento.add(menuItemReceber);

        jMenuBar1.add(menuMovimento);

        menuItemControleEstoque.setText("Pesquisar");

        menuItemEstoque.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        menuItemEstoque.setText("Pesquisar no Estoque");
        menuItemEstoque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemEstoqueActionPerformed(evt);
            }
        });
        menuItemControleEstoque.add(menuItemEstoque);

        jMenuBar1.add(menuItemControleEstoque);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(dpDesktop, javax.swing.GroupLayout.DEFAULT_SIZE, 799, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(dpDesktop, javax.swing.GroupLayout.DEFAULT_SIZE, 570, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-815)/2, (screenSize.height-629)/2, 815, 629);
    }// </editor-fold>//GEN-END:initComponents

    private void menuItemClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemClienteActionPerformed
}//GEN-LAST:event_menuItemClienteActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        if (!CadastroClientes.getInstancia().isVisible()) {
            dpDesktop.add(CadastroClientes.getInstancia());
        }
        CadastroClientes.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void FornecedorCadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FornecedorCadastroActionPerformed
        if (!CadastroFornecedor.getInstancia().isVisible()) {
            dpDesktop.add(CadastroFornecedor.getInstancia());
        }
        CadastroFornecedor.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_FornecedorCadastroActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        if (!CadastroFuncionario.getInstancia().isVisible()) {
            dpDesktop.add(CadastroFuncionario.getInstancia());
        }
        CadastroFuncionario.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        if (!CadastroProduto.getInstancia().isVisible()) {
            dpDesktop.add(CadastroProduto.getInstancia());
        }
        CadastroProduto.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void menuItemVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemVendaActionPerformed
        if (!Vendas.getInstancia().isVisible()) {
            dpDesktop.add(Vendas.getInstancia());
        }
        Vendas.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_menuItemVendaActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
       
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void menuMovimentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuMovimentoActionPerformed
    }//GEN-LAST:event_menuMovimentoActionPerformed

    private void menuItemPagarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemPagarActionPerformed
        if (!contasPagar.getInstancia().isVisible()) {
            dpDesktop.add(contasPagar.getInstancia());
        }
        contasPagar.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_menuItemPagarActionPerformed

    private void menuItemEstoqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemEstoqueActionPerformed
       if (!controleEstoque.getInstancia().isVisible()) {
            dpDesktop.add(controleEstoque.getInstancia());
        }
        controleEstoque.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_menuItemEstoqueActionPerformed

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
        
    }//GEN-LAST:event_jMenuItem9ActionPerformed

    private void menuItemReceberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemReceberActionPerformed
       if (!contasReceber.getInstancia().isVisible()) {
            dpDesktop.add(contasReceber.getInstancia());
        }
        contasReceber.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_menuItemReceberActionPerformed

    private void menuItemCompraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemCompraActionPerformed
     if (!Compras.getInstancia().isVisible()) {
            dpDesktop.add(Compras.getInstancia());
        }
        Compras.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_menuItemCompraActionPerformed

    private void btnFuncionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFuncionarioActionPerformed
        if (!CadastroFuncionario.getInstancia().isVisible()) {
            dpDesktop.add(CadastroFuncionario.getInstancia());
        }
        CadastroFuncionario.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
}//GEN-LAST:event_btnFuncionarioActionPerformed

    private void btnProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProdutoActionPerformed
        if (!CadastroProduto.getInstancia().isVisible()) {
            dpDesktop.add(CadastroProduto.getInstancia());
        }
        CadastroProduto.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
}//GEN-LAST:event_btnProdutoActionPerformed

    private void btnFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFornecedorActionPerformed
        if (!CadastroFornecedor.getInstancia().isVisible()) {
            dpDesktop.add(CadastroFornecedor.getInstancia());
        }
        CadastroFornecedor.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
}//GEN-LAST:event_btnFornecedorActionPerformed

    private void tabAniversarioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabAniversarioMouseClicked

}//GEN-LAST:event_tabAniversarioMouseClicked

    private void tabEstoqueMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabEstoqueMouseClicked

}//GEN-LAST:event_tabEstoqueMouseClicked

    private void btnClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClienteActionPerformed
        if (!CadastroClientes.getInstancia().isVisible()) {
            dpDesktop.add(CadastroClientes.getInstancia());
        }
        CadastroClientes.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
}//GEN-LAST:event_btnClienteActionPerformed

    private void btnContasReceberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnContasReceberActionPerformed
         if (!contasReceber.getInstancia().isVisible()) {
            dpDesktop.add(contasReceber.getInstancia());
        }
        contasReceber.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_btnContasReceberActionPerformed

    private void btnComprasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnComprasActionPerformed
        if (!Compras.getInstancia().isVisible()) {
            dpDesktop.add(Compras.getInstancia());
        }
        Compras.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_btnComprasActionPerformed

    private void btnPesquisarEstoqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarEstoqueActionPerformed
      if (!controleEstoque.getInstancia().isVisible()) {
            dpDesktop.add(controleEstoque.getInstancia());
        }
        controleEstoque.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_btnPesquisarEstoqueActionPerformed

    private void btnContasPagarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnContasPagarActionPerformed
 if (!contasPagar.getInstancia().isVisible()) {
            dpDesktop.add(contasPagar.getInstancia());
        }
        contasPagar.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();        // TODO add your handling code here:
    }//GEN-LAST:event_btnContasPagarActionPerformed

    private void btnVendasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVendasActionPerformed
     if (!Vendas.getInstancia().isVisible()) {
            dpDesktop.add(Vendas.getInstancia());
        }
        Vendas.getInstancia().primeiraLeitura();
        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
    }//GEN-LAST:event_btnVendasActionPerformed

    private void dadosAniversario() {
        modeloAniversario.setNumRows(0);

        ArrayList<Cliente> listaCliente;

        try {

            dao = new ClienteDAO();
            String data = new SimpleDateFormat("dd/MM").format(new Date()).toString();
            listaCliente = dao.retornaAniversariante(data);

            for (Cliente c : listaCliente) {
                modeloAniversario.addRow(new String[]{c.getNome(), c.getTamanho()});
            }

        } catch (SQLException ex) {
           JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }

    }

    private void dadosAlerta() {

        modeloEstoque.setNumRows(0);

        ArrayList<Produto> listaProduto = new ArrayList<Produto>();

        try {

            ProdutoDAO pdao = new ProdutoDAO();

            listaProduto = pdao.RetornaTodosProdutos();

            EstoqueDAO edao = new EstoqueDAO();

            for (Produto p : listaProduto) {
                if (edao.verificarAlertaProduto(p) == true) {
                    modeloEstoque.addRow(new String[]{Integer.toString(p.getCodProduto()), p.getNome()});
                }
            }

        } catch (SQLException ex) {
                       JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }

    }

    private void formWindowOpenedAniversario(java.awt.event.WindowEvent evt) {


        //TABELA ANIVERSARIO
        String[] colunasAniversario = new String[]{"", ""};
        String[][] dadosAniversario = new String[][]{};

        modeloAniversario = new DefaultTableModel(dadosAniversario, colunasAniversario);

        tabAniversario.setModel(modeloAniversario);
        tabAniversario.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("Nome");
        tabAniversario.getTableHeader().getColumnModel().getColumn(1).setHeaderValue("Tamanho");


        tabAniversario.getColumnModel().getColumn(0).setPreferredWidth(300);
        tabAniversario.setPreferredScrollableViewportSize(new Dimension(2300, 0));

    }

    private void formWindowOpenedAlerta(java.awt.event.WindowEvent evt) {
        //TABELA ALERTA DE ESTOQUE
        String[] colunasEstoque = new String[]{"", ""};
        String[][] dadosEstoque = new String[][]{};

        modeloEstoque = new DefaultTableModel(dadosEstoque, colunasEstoque);

        tabEstoque.setModel(modeloEstoque);
        tabEstoque.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("Código");
        tabEstoque.getTableHeader().getColumnModel().getColumn(1).setHeaderValue("Nome");


        tabEstoque.getColumnModel().getColumn(1).setPreferredWidth(400);
        tabEstoque.setPreferredScrollableViewportSize(new Dimension(2300, 0));



    }

    public void primeiraLeitura() {


        formWindowOpenedAniversario(null);
        formWindowOpenedAlerta(null);
        dadosAlerta();
        dadosAniversario();
        setVisible(true);


    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {

                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
                }

                new TelaPrincipal().primeiraLeitura();
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem FornecedorCadastro;
    private javax.swing.JButton btnCliente;
    private javax.swing.JButton btnCompras;
    private javax.swing.JButton btnContasPagar;
    private javax.swing.JButton btnContasReceber;
    private javax.swing.JButton btnFornecedor;
    private javax.swing.JButton btnFuncionario;
    private javax.swing.JButton btnPesquisarEstoque;
    private javax.swing.JButton btnProduto;
    private javax.swing.JButton btnVendas;
    private javax.swing.JDesktopPane dpDesktop;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPopupMenu.Separator jSeparator3;
    private javax.swing.JMenu menuCadastro;
    private javax.swing.JMenuItem menuItemCompra;
    private javax.swing.JMenu menuItemControleEstoque;
    private javax.swing.JMenuItem menuItemEstoque;
    private javax.swing.JMenuItem menuItemPagar;
    private javax.swing.JMenuItem menuItemReceber;
    private javax.swing.JMenuItem menuItemVenda;
    private javax.swing.JMenu menuMovimento;
    private javax.swing.JTable tabAniversario;
    private javax.swing.JTable tabEstoque;
    // End of variables declaration//GEN-END:variables
}
